home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / TransSkel Pascal 2.5 / TransSkel / MultiSkel ƒ / MSkelEdit.p < prev    next >
Encoding:
Text File  |  1988-12-09  |  3.4 KB  |  178 lines  |  [TEXT/PJMM]

  1. {    TransSkel multiple-window demonstration: TextEdit module}
  2.  
  3. {    This module handles a simple TextEdit window, in which text may be}
  4. {    typed and standard Cut/Copy/Paste/Clear operations may be performed.}
  5. {    Undo is not supported, nor is text scrolling.}
  6.  
  7. {    14 June 1986        Paul DuBois}
  8. {    7 January 1987    Owen Hartnett    }
  9. {    30 December 1987 OH changed for version 1.03 }
  10.  
  11. unit MSkelEdit;
  12.  
  13. interface
  14.  
  15.     uses
  16. {$IFC UNDEFINED THINK_PASCAL}
  17.         Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, 
  18. {$ENDC}
  19.         MultiSkelGlobals, common, TransSkel;
  20.  
  21.     procedure EditWindInit;
  22.     procedure EditWindEditMenu (item: integer);
  23.  
  24.  
  25. implementation
  26. { edit menu item numbers }
  27.  
  28.     const
  29.         undo = 1;
  30.         cut = 3;
  31.         copy = 4;
  32.         paste = 5;
  33.         clear = 6;
  34.  
  35.     var
  36.         teEdit: TEHandle;        { handle to text window TextEdit record }
  37.  
  38.     procedure Halt;
  39.  
  40.     begin
  41.         TEDispose(teEdit);
  42.         CloseWindow(editWind);
  43.     end;
  44.  
  45.     procedure Idle;
  46.  
  47.     begin
  48.         TEIdle(teEdit);    { blink that cursor! }
  49.     end;
  50.  
  51.     procedure key (ch: char; mods: integer);
  52.  
  53.     begin
  54.         TEKey(ch, teEdit);
  55.     end;
  56.  
  57.  
  58.     procedure Mouse (thePt: Point; t: longint; mods: integer);
  59.     begin
  60.         TEClick(thePt, Boolean(BitAnd(mods, shiftKey)), teEdit);
  61.     end;
  62.  
  63. {    Update text window.  The update event might be in response to a}
  64. {    window resizing.  If so, resize the rects and recalc the linestarts}
  65. {    of the text.  To resize the rects, only the right edge of the}
  66. {    destRect need be changed (the bottom is not used, and the left and}
  67. {    top should not be changed). The viewRect should be sized to the}
  68. {    screen.}
  69.  
  70.     procedure Update (resized: Boolean);
  71.  
  72.         var
  73.             r: Rect;
  74.  
  75.     begin
  76.         r := editWind^.portRect;
  77.         EraseRect(r);
  78.         r.left := r.left + 4;
  79.         r.bottom := r.bottom - 2;
  80.         r.top := r.top + 2;
  81.         r.right := r.right - 19;
  82.         if resized then
  83.             begin
  84.                 teEdit^^.destRect.right := r.right;
  85.                 teEdit^^.viewRect := r;
  86.                 TECalText(teEdit);
  87.             end;
  88.         DrawGrowBox(editWind);
  89.         TEUpdate(r, teEdit);
  90.     end;
  91.  
  92.     procedure Activate (active: Boolean);
  93.  
  94.     begin
  95.         DrawGrowBox(editWind);
  96.         if active then
  97.             begin
  98.                 TEActivate(teEdit);
  99.                 DisableItem(editMenu, undo);
  100.             end
  101.         else
  102.             begin
  103.                 TEDeactivate(teEdit);
  104.                 EnableItem(editMenu, undo);
  105.             end;
  106.     end;
  107.  
  108. {    Handle Edit menu items for text window}
  109.  
  110.     procedure EditWindEditMenu;
  111.  
  112.         var
  113.             ignore: integer;
  114.     begin
  115.         case item of
  116.             cut: 
  117.  
  118. {    cut selection, put in TE Scrap, clear clipboard and put}
  119. {    TE scrap in it}
  120.  
  121.                 begin
  122.                     TECut(teEdit);
  123.                     ignore := ZeroScrap;
  124.                     ignore := TEToScrap;
  125.                 end;
  126.             copy: 
  127.  
  128. {    copy selection to TE Scrap, clear clipboard and put}
  129. {    TE scrap in it}
  130.  
  131.                 begin
  132.                     TECopy(teEdit);
  133.                     ignore := zeroscrap;
  134.                     ignore := TEToScrap;
  135.                 end;
  136.             paste: 
  137.  
  138. {    get clipboard into TE scrap, put TE scrap into edit record}
  139.  
  140.                 begin
  141.                     ignore := TEFromScrap;
  142.                     TEPaste(teEdit);
  143.                 end;
  144.             clear: 
  145.  
  146. {    delete selection without putting into TE scrap or clipboard}
  147.  
  148.                 TEDelete(teEdit);
  149.             otherwise
  150.                 ;
  151.         end;
  152.     end;
  153.  
  154.     procedure EditWindInit;
  155.         var
  156.             r: Rect;
  157.             str: str255;
  158.             kludge: longint;
  159.             strptr: Ptr;
  160.  
  161.     begin
  162.         editWind := GetNewWindow(editWindRes, nil, WindowPtr(-1));
  163.         dummy := SkelWindow(editWind, @Mouse, @Key, @Update, @Activate, nil, @Halt, @Idle, true);
  164.         TextFont(0);
  165.         TextSize(0);
  166.         r := editWind^.portRect;
  167.         r.left := r.left + 4;
  168.         r.bottom := r.bottom - 2;
  169.         r.top := r.top + 2;
  170.         r.right := r.right - 19;
  171.         teEdit := TENew(r, r);
  172.         str := 'This is the text editing window.';
  173.         strPtr := @str;
  174.         kludge := longint(strPtr) + 1;
  175.         strPtr := Ptr(kludge);
  176.         TEInsert(strPtr, longint(length(str)), teEdit);
  177.     end;
  178. end.